home *** CD-ROM | disk | FTP | other *** search
- Path: news.iastate.edu!usenet
- From: Steve Lee <sjlee@iastate.edu>
- Newsgroups: comp.lang.c++
- Subject: Static Member Functions
- Date: Sun, 18 Feb 1996 11:30:46 -0800
- Organization: Iowa State University
- Message-ID: <31277E66.687F@iastate.edu>
- NNTP-Posting-Host: dial47.ppp.iastate.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6b (Win16; I)
-
- Hi,
-
- I have a couple of questions about static member functions.
-
- 1) I was wondering why C++ doesn't provide (or maybe it does and I don't) a way to protect a
- static member function by making it constant. What I had in mind was something like the usage of
- const for a member function. I know that in this sense, it is making the implicit variable *this
- constant, and that static member functions don't have an implicit *this variable since they don't
- act on a specific object. I want to know why this, or something similar isn't possible.
-
- class foo {
-
- static int GetCount() const;
- static int count;
- };
-
- 2) In the example above, count is private. I find it interesting though that any piece of code
- can initialize the private variable count. Isn't this contradictory? The only thing I can think
- of is that the linker only allows it to be initialized once (obviously), and if the implementor
- of the class initializes it, then no users will be able to without a linker error.
-
- Thanks in advance.
-
- --
- Steve Lee
- Computer Engineering/Computer Science
- Iowa State University
- email -> sjlee@iastate.edu
- WWW -> http://www.cs.iastate.edu/~sjlee/homepage.html
-